﻿using Clancy.Interfaces;
using ReactiveUI;
using System;
using System.Reactive.Subjects;

namespace Clancy.Ui.ViewModels
{
    public class TeachThresholdViewModel : ClancyEditorViewModelBase
    {
        private ObservableAsPropertyHelper<double> m_AverageActivityLevelPropertyHelper;
        private ObservableAsPropertyHelper<double> m_AverageSilenceLevelPropertyHelper;
        private BehaviorSubject<double> m_AvgActivityLevel = new BehaviorSubject<double>(0);
        private BehaviorSubject<double> m_AvgSilenceLevel = new BehaviorSubject<double>(0);
        private ObservableAsPropertyHelper<double> m_EstimatedThresholdLevelPropertyHelper;
        private BehaviorSubject<double> m_EstThresholdLevel = new BehaviorSubject<double>(0);

        public TeachThresholdViewModel(IOperationalAdapterProvider operationalAdapterProvider, ISurveilanceStorage surveilanceStorage)
            : base(operationalAdapterProvider, surveilanceStorage)
        {
            InitCommands();

            InitProperties();
        }

        public double AverageActivityLevel
        {
            get { return m_AverageActivityLevelPropertyHelper.Value; }
        }

        public double AverageSilenceLevel
        {
            get { return m_AverageSilenceLevelPropertyHelper.Value; }
        }

        public ReactiveCommand<object> CmdCommit { get; private set; }

        public ReactiveCommand<object> CmdResetTeaching { get; private set; }

        public ReactiveCommand<object> CmdStartLearn { get; private set; }

        public ReactiveCommand<object> CmdStartTeachActivity { get; private set; }

        public ReactiveCommand<object> CmdStartTeachSilence { get; private set; }

        public ReactiveCommand<object> CmdStopLearn { get; private set; }

        public ReactiveCommand<object> CmdStopTeachActivity { get; private set; }

        public ReactiveCommand<object> CmdStopTeachSilence { get; private set; }

        public double EstimatedThresholdLevel
        {
            get { return m_EstimatedThresholdLevelPropertyHelper.Value; }
        }

        private void Commit()
        {
            throw new NotImplementedException();
        }

        private void InitCommands()
        {
            CmdCommit = ReactiveCommand.Create();
            CmdCommit.Subscribe(_ => Commit());
            DisposableRxElements.Add(CmdCommit);

            CmdStartLearn = ReactiveCommand.Create();
            CmdStartLearn.Subscribe(_ => StartLearn());
            DisposableRxElements.Add(CmdStartLearn);

            CmdStopLearn = ReactiveCommand.Create();
            CmdStopLearn.Subscribe(_ => StopLearn());
            DisposableRxElements.Add(CmdStopLearn);

            CmdResetTeaching = ReactiveCommand.Create();
            CmdResetTeaching.Subscribe(_ => Reset());
            DisposableRxElements.Add(CmdResetTeaching);

            CmdStartTeachActivity = ReactiveCommand.Create();
            CmdStartTeachActivity.Subscribe(_ => StartTeachActivity());
            DisposableRxElements.Add(CmdStartTeachActivity);

            CmdStopTeachActivity = ReactiveCommand.Create();
            CmdStopTeachActivity.Subscribe(_ => StopTeachActivity());
            DisposableRxElements.Add(CmdStopTeachActivity);

            CmdStartTeachSilence = ReactiveCommand.Create();
            CmdStartTeachSilence.Subscribe(_ => StartTeachSilence());
            DisposableRxElements.Add(CmdStartTeachSilence);

            CmdStopTeachSilence = ReactiveCommand.Create();
            CmdStopTeachSilence.Subscribe(_ => StopTeachSilence());
            DisposableRxElements.Add(CmdStopTeachSilence);
        }

        private void InitProperties()
        {
            m_AverageActivityLevelPropertyHelper = new ObservableAsPropertyHelper<double>(m_AvgActivityLevel, _ => this.RaisePropertyChanged("AverageActivityLevel"));
            DisposableRxElements.Add(m_AverageActivityLevelPropertyHelper);

            m_AverageSilenceLevelPropertyHelper = new ObservableAsPropertyHelper<double>(m_AvgSilenceLevel, _ => this.RaisePropertyChanged("AverageSilenceLevel"));
            DisposableRxElements.Add(m_AverageSilenceLevelPropertyHelper);

            m_EstimatedThresholdLevelPropertyHelper = new ObservableAsPropertyHelper<double>(m_EstThresholdLevel, _ => this.RaisePropertyChanged("EstimatedThresholdLevel"));
            DisposableRxElements.Add(m_EstimatedThresholdLevelPropertyHelper);
        }

        private void Reset()
        {
            throw new NotImplementedException();
        }

        private void StartLearn()
        {
            throw new NotImplementedException();
        }

        private void StartTeachActivity()
        {
            throw new NotImplementedException();
        }

        private void StartTeachSilence()
        {
            throw new NotImplementedException();
        }

        private void StopLearn()
        {
            throw new NotImplementedException();
        }

        private void StopTeachActivity()
        {
            throw new NotImplementedException();
        }

        private void StopTeachSilence()
        {
            throw new NotImplementedException();
        }
    }
}